package summary;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: 海琳琦
 * @Date: 2022/8/17 16:25
 * https://leetcode.cn/problems/day-of-the-year/
 */
public class Title1154 {

    public static int dayOfYear(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = null;
        try {
            parse = sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(parse);
        return calendar.get(Calendar.DAY_OF_YEAR);
    }

    public static void main(String[] args) throws ParseException {
        Calendar c = Calendar.getInstance();
        // year年的3月1日
        c.set(2022, 2, 1);
        //将3月1日往左偏移一天结果是2月的天数
        c.add(Calendar.DAY_OF_MONTH, -1);
        System.out.println(c.get(Calendar.DAY_OF_MONTH));
    }
}
